﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;

namespace DbSharp.Tools.DbConnectionBuilder.Core.Plugin
{
    class PluginNamePair
    {
        public PluginNamePair(string providerName)
        {
            ProviderName = providerName;
        }


        private string ToStringWithProviderName()
        {
            string result;
            if (string.IsNullOrEmpty(DisplayName))
                result = string.Empty;
            else
                result = DisplayName;

            if (string.IsNullOrEmpty(ProviderName))
                result = result + string.Empty;
            else
                result = result + ProviderName;
            return result;
        }


        
        public string DisplayName { get; set; }
        public string ProviderName { get; set; }

        public override string ToString()
        {
            if (string.IsNullOrEmpty(DisplayName))
                return string.Empty;
            else
                return DisplayName;
        }


        public override bool Equals(object obj)
        {
            var pair = obj as PluginNamePair;
            if ((pair == null) && (this != null))
            {
                return false;
            }

            if (string.Equals(pair.ProviderName, ProviderName, StringComparison.OrdinalIgnoreCase)
                && string.Equals(pair.DisplayName, DisplayName, StringComparison.OrdinalIgnoreCase))
                return true;
            else
                return false;
        }

        public override int GetHashCode()
        {
            return ToStringWithProviderName().GetHashCode();
        }
    }

    
    interface IDbConnectionPlugin
    {
        PluginNamePair PluginNamePair { get; }
        DbConnectionStringBuilder CreateConnectionStrBuilder(DbServerCredential credential);
        DbServerCredential CreateCredential(string connectionString);
        DbConnection CreateDbConnection(string connectionString);

        /// <summary>
        /// List Excel/Access internal version and application version
        /// Just for Access and Excel. 
        /// </summary>
        /// <returns>Return candidate database file version</returns>
        List<FileVersionPair> GetCandidateDbFileVersionPairs();
    }

 
}
